package com.zrrd._12_javaSE_Plus.reflect.no_16;

import java.lang.reflect.Field;

/**
 * @author WanJl
 * @version 1.0
 * @title No_16
 * @description
 * @create 2023/11/18 16:28
 */
public class No_16 {
    /**
     * @param className 类名参数
     * @return 该类的所有属性名和属性类型
     * @throws Exception
     */
    public static String getAllFields(String className) throws Exception {
        StringBuilder builder = new StringBuilder();
        //1.获取Class对象
        Class<?> clazz = Class.forName(className);
        //2.获取属性对象
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            builder.append(field).append("\n");
        }
        return builder.toString();
    }

    public static void main(String[] args) throws Exception {
        System.out.println(getAllFields("java.lang.String"));
    }
}
